--local cmdTrackingCommand = RunMacroText(".track name " .. objToTrack)
local objToTrack

function ccR_MoP_Treasure_Tracking()
	if ccRS.CF_Treasure_Tracking then
		if not frMTT then frMTT = CreateFrame("Frame") end;
		if frMTT then 
			frMTT:RegisterEvent("ZONE_CHANGED")
			frMTT:RegisterEvent("PLAYER_ENTERING_WORLD")
			frMTT:SetScript("OnEvent", frMTT_OnEvent)
		end;
	else
		if frMTT then frMTT:SetScript("OnEvent", nil) end;
		ccrMoP_Treasure_Tracking_Disable()
	end
end

function ccrMoP_Treasure_Tracking_Disable()
	PrintToChat("MoP Treasure Tracking Disabled")
	for i = 0, # tblUldum do 
		objToTrack = tblUldum[i]
		if objToTrack ~= nil and GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
	end
	for i = 0, # tblJadeForest do 
		objToTrack = tblJadeForest[i]
		if objToTrack ~= nil and GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
	end
	for i = 0, # tblDreadWastes do 
		objToTrack = tblDreadWastes[i]
		if objToTrack ~= nil and GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
	end		
	for i = 0, # tblKrasarangWilds do 
		objToTrack = tblKrasarangWilds[i]
		if objToTrack ~= nil and GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
	end
	for i = 0, # tblKunLaiSummit do 
		objToTrack = tblKunLaiSummit[i]
		if objToTrack ~= nil and GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
	end
	for i = 0, # tblVeiledStair do 
		objToTrack = tblVeiledStair[i]
		if objToTrack ~= nil and GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
	end
	for i = 0, # tblTownlongSteppes do 
		objToTrack = tblTownlongSteppes[i]
		if objToTrack ~= nil and GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
	end
	for i = 0, # tblValleyOfTheFourWinds do 
		objToTrack = tblValleyOfTheFourWinds[i]
		if objToTrack ~= nil and GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
	end
	for i = 0, # tblIsleOfThunder do 
		objToTrack = tblIsleOfThunder[i]
		if objToTrack ~= nil and GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
	end	
end
function frMTT_OnEvent(self, event, ...)
	if event == "ZONE_CHANGED" or event == "PLAYER_ENTERING_WORLD" then
		local vZone = GetRealZoneText()
		-- Uldum
		if vZone == "Uldum" then
			for i = 1, # tblUldum do 
				objToTrack = tblUldum[i]
				if GetTrackingState(objToTrack) == false then TrackByName(objToTrack) end;				
			end
		else
			for i = 1, # tblUldum do 
				objToTrack = tblUldum[i]
				if GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
			end			
		end

		-- Jade Forest
		if vZone == "The Jade Forest" then
			for i = 1, # tblJadeForest do 
				objToTrack = tblJadeForest[i]
				if GetTrackingState(objToTrack) == false then TrackByName(objToTrack) end;				
			end
		else
			for i = 1, # tblJadeForest do 
				objToTrack = tblJadeForest[i]
				if GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
			end			
		end
		-- Dread Wastes
		if vZone == "Dread Wastes" then
			for i = 1, # tblDreadWastes do 
				objToTrack = tblDreadWastes[i]
				if GetTrackingState(objToTrack) == false then TrackByName(objToTrack) end;				
			end
		else
			for i = 1, # tblDreadWastes do 
				objToTrack = tblDreadWastes[i]
				if GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
			end		
		end
		-- Krasarang Wilds
		if vZone == "Krasarang Wilds" then
			for i = 1, # tblKrasarangWilds do 
				objToTrack = tblKrasarangWilds[i]
				if GetTrackingState(objToTrack) == false then TrackByName(objToTrack) end;				
			end
		else
			for i = 1, # tblKrasarangWilds do 
				objToTrack = tblKrasarangWilds[i]
				if GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
			end	
		end
		-- Kun-Lai Summit
		if vZone == "Kun-Lai Summit" then
			for i = 1, # tblKunLaiSummit do 
				objToTrack = tblKunLaiSummit[i]
				if GetTrackingState(objToTrack) == false then TrackByName(objToTrack) end;				
			end
		else
			for i = 1, # tblKunLaiSummit do 
				objToTrack = tblKunLaiSummit[i]
				if GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
			end	
		end
		-- The Veiled Stair
		if vZone == "The Veiled Stair" then
			for i = 1, # tblVeiledStair do 
				objToTrack = tblVeiledStair[i]
				if GetTrackingState(objToTrack) == false then TrackByName(objToTrack) end;				
			end
		else
			for i = 1, # tblVeiledStair do 
				objToTrack = tblVeiledStair[i]
				if GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
			end	
		end
		-- Townlong Steppes
		if vZone == "Townlong Steppes" then
			for i = 1, # tblTownlongSteppes do 
				objToTrack = tblTownlongSteppes[i]
				if GetTrackingState(objToTrack) == false then TrackByName(objToTrack) end;				
			end
		else
			for i = 1, # tblTownlongSteppes do 
				objToTrack = tblTownlongSteppes[i]
				if GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
			end	
		end
		-- Valley of the Four Winds
		if vZone == "Valley of the Four Winds" then
			for i = 1, # tblValleyOfTheFourWinds do 
				objToTrack = tblValleyOfTheFourWinds[i]
				if GetTrackingState(objToTrack) == false then TrackByName(objToTrack) end;				
			end
		else
			for i = 1, # tblValleyOfTheFourWinds do 
				objToTrack = tblValleyOfTheFourWinds[i]
				if GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
			end	
		end
		-- Isle of Thunder
		if vZone == "Isle of Thunder" then
			for i = 1, # tblIsleOfThunder do 
				objToTrack = tblIsleOfThunder[i]
				if GetTrackingState(objToTrack) == false then TrackByName(objToTrack) end;				
			end
		else
			for i = 1, # tblIsleOfThunder do 
				objToTrack = tblIsleOfThunder[i]
				if GetTrackingState(objToTrack) == true then TrackByName(objToTrack) end;				
			end	
		end		
	end
end
tblUldum = {
	"Mysterious Camel Figurine";
}
tblIsleOfThunder = {
	"Trove of the Thunder King";
}
tblJadeForest = {
	"Ancient Pandaren Tea Pot";
	"Ancient Pandaren Mining Pick";
	"Hammer of Ten Thunders";
	"Lucky Pandaren Coin";
	"Pandaren Ritual Stone";
	"Ship's Storage";
	"Stash of Gems";
	"Wodin's Mantid Shanker";
	"Offering of Rememberance";
	"Jade Warrior Statue"; -- Jade Witch
	"Ship's Locker";
	--"Dark Soil";	-- Tillers
}
tblDreadWastes = {
	"Blade of the Prime";
	"Bloodsoaked Chitin Fragment";
	"Dissector's Staff of Mutation";
	"Amber Encased Necklace";					-- Lucid Amulet of the Agile Mind
	"Malik's Stalwart Spear";
	"Glinting Rapana Whelk";					-- Manipulator's Talisman
	"Swarming Cleaver of Ka'roz";
	"Wind-Reaver's Dagger of Quick Strikes";
	"Swarmkeeper's Crossbow";					-- FLAG
	"Bloodseeker's Frenzied Mace";				-- FLAG
	"Box of Supplies";							-- FLAG
	"Hammer of the Poisoned Mind";				-- FLAG
	--"Dark Soil";	-- Tillers
}
tblKrasarangWilds = {
	"Barrel of Banana Infused Rum";
	"Stack of Papers";
	"Equipment Locker";
	"Pandaren Fishing Spear";
	"Saurok Stone Tablet";
	--"Dark Soil";	-- Tillers
}
tblKunLaiSummit = {
	"Tablet of Ren Yun";
	"Ancient Mogu Tablet";
	"Hozen Warrior Spear";
	"Rikktik's Tick Remover";
	"Sprite's Cloth Chest";
	"Statue of Xuen";
	"Stolen Sprite Treasure";
	"Terracotta Head";
	"Hozen Treasure Cache";
	"Lost Adventurer's Belongings";
	"Mo-Mo's Treasure Chest";
	"Stash of Yaungol Weapons";
	"Frozen Trail Packer";			-- Kafa Press
	--"Dark Soil";	-- Tillers
}
tblVeiledStair = {
	"Forgotten Lockbox";
	"The Hammer of Folly";
	"Dark Soil";	-- Tillers
}
tblTownlongSteppes = {
	"Abandoned Crate of Goods";
	"Fragment of Dread";
	"Hardened Sap of Kri'vess";
	"Yaungol Fire Carrier";
	"Amber Encased Moth";
	--"Dark Soil";	-- Tillers
}
tblValleyOfTheFourWinds = {
	"Boat-Building Instructions";
	"Ghostly Pandaren Fisherman"; 	-- Ancient Pandaren Fishing Lure
	"Ghostly Pandaren Craftsman"; 	-- Ancient Pandaren Woodcutter"
	"Staff of the Hidden Master";
	"Virmen Treasure Cache";
	"Cache of Pilfered Goods";
	--"Dark Soil";	-- Tillers
}